package cn.idev.excel.analysis.v03.handlers;

import cn.idev.excel.analysis.v03.IgnorableXlsRecordHandler;
import cn.idev.excel.context.xls.XlsReadContext;
import cn.idev.excel.enums.RowTypeEnum;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.ReadCellData;
import cn.idev.excel.util.StringUtils;
import org.apache.poi.hssf.record.LabelRecord;
import org.apache.poi.hssf.record.Record;

/**
 * Record handler
 */
public class LabelRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler {
    @Override
    public void processRecord(XlsReadContext xlsReadContext, Record record) {
        LabelRecord lrec = (LabelRecord) record;
        String data = lrec.getValue();
        if (data != null) {
            GlobalConfiguration globalConfiguration =
                    xlsReadContext.currentReadHolder().globalConfiguration();
            if (globalConfiguration.getAutoStrip()) {
                data = StringUtils.strip(data);
            } else if (globalConfiguration.getAutoTrim()) {
                data = data.trim();
            }
        }
        xlsReadContext
                .xlsReadSheetHolder()
                .getCellMap()
                .put((int) lrec.getColumn(), ReadCellData.newInstance(data, lrec.getRow(), (int) lrec.getColumn()));
        xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA);
    }
}
